/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { Utility as ref } from './Utility.js';
import { XMLDOMImplementation } from './XMLDOMImplementation.js';
import { XMLDocument } from './XMLDocument.js';
import { XMLDocumentCB } from './XMLDocumentCB.js';
import { XMLStringWriter } from './XMLStringWriter.js';
import { XMLStreamWriter } from './XMLStreamWriter.js';
import { NodeType } from './NodeType.js';
import { WriterState } from './WriterState.js';

// Generated by CoffeeScript 1.12.7
let index = {}

let assign = ref.assign;
let isFunction = ref.isFunction;


index.create = function (name, xmldec, doctype, options) {
  var doc, root;
  if (name == null) {
    throw new Error("Root element needs a name.");
  }
  options = assign({}, xmldec, doctype, options);
  doc = new XMLDocument(options);
  root = doc.element(name);
  if (!options.headless) {
    doc.declaration(options);
    if ((options.pubID != null) || (options.sysID != null)) {
      doc.dtd(options);
    }
  }
  return root;
};

index.begin = function (options, onData, onEnd) {
  var ref1;
  if (isFunction(options)) {
    ref1 = [options, onData], onData = ref1[0], onEnd = ref1[1];
    options = {};
  }
  if (onData) {
    return new XMLDocumentCB(options, onData, onEnd);
  } else {
    return new XMLDocument(options);
  }
};

index.stringWriter = function (options) {
  return new XMLStringWriter(options);
};

index.streamWriter = function (stream, options) {
  return new XMLStreamWriter(stream, options);
};

index.implementation = new XMLDOMImplementation();

index.nodeType = NodeType;

index.writerState = WriterState;

export { index }

